package co.fitstart.entity.user.investigation;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;

import com.alibaba.fastjson.annotation.JSONField;
import com.demo2do.core.format.PersistentFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.reference.Gender;
import co.fitstart.entity.user.User;
import co.fitstart.entity.user.fit.Shape;

/**
 * 
 * @author mohanlan
 * 与fit record 二取其一，主要用于记录线上调查问卷。
 * 老逻辑中用户个人中心的身体数据可以修改编辑的（UserFit）。
 * 线上问卷调查也有这个调查。
 * 
 */
@Entity
@Table(name = "fit_investigation")
@DynamicUpdate
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class FitInvestigation {
    
    @Id
    @GeneratedValue
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JSONField(serialize = false)
    private User user;
    
    /** 创建时间 */
    private Date createTime;
    
    private Integer height;
    
    private Float weight;
    
    private Integer age;
    
    @Enumerated(EnumType.ORDINAL)
    private Gender gender;
    
    /** BMI 值 */
    private BigDecimal bmiValue;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private Shape shape;
    
    /**
     * The default constructor
     */
    public FitInvestigation() {
    }

    /**
     * 
     * @return
     */
    public FitInvestigation initialize() {
        this.createTime = new Date();
        return this;
    }

    /**
     * @param fitInvestigation
     * @return
     */
    public FitInvestigation edit(FitInvestigation fitInvestigation) {
        
        this.height = fitInvestigation.getHeight();
        this.weight = fitInvestigation.getWeight();
        this.age = fitInvestigation.getAge();
        this.gender = fitInvestigation.getGender();
        
        return this;
    }

    /**
     * @param user
     * @return
     */
    public FitInvestigation bindUser(User user) {
        this.user = user;
        return this;
    }
    
    /**
     * 
     * @param bmiValue
     * @return
     */
    public FitInvestigation editBmiValue(BigDecimal bmiValue) {
        this.bmiValue = bmiValue;
        return this;
    }

    public Long getId() {
        return id;
    }

    public User getUser() {
        return user;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public Integer getHeight() {
        return height;
    }

    public Float getWeight() {
        return weight;
    }

    public Integer getAge() {
        return age;
    }

    public Gender getGender() {
        return gender;
    }

    public BigDecimal getBmiValue() {
        return bmiValue;
    }

    public Shape getShape() {
        return shape;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public void setWeight(Float weight) {
        this.weight = weight;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public void setBmiValue(BigDecimal bmiValue) {
        this.bmiValue = bmiValue;
    }

    public void setShape(Shape shape) {
        this.shape = shape;
    }
}
